package com.wwp.tbshop.activity.cartactivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.wwp.tbshop.R;
import com.wwp.tbshop.util.Constant;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

//import com.wwp.tbshop.R;


/**
 * Created by windows on 2017/6/15.
 */

public class DeliverGoodsActivity extends Activity {
    @Bind(R.id.tv_shopcart_edit)
    TextView mTvShopcartEdit;
    @Bind(R.id.cash_pay)
    TextView mCashPay;
    @Bind(R.id.iv_one)
    ImageView mIvOne;
    @Bind(R.id.iv_second)
    ImageView mIvSecond;
    @Bind(R.id.iv_third)
    ImageView mIvThird;
    @Bind(R.id.tv_commit)
    TextView mTvCommit;

    List<ImageView> mImagView = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_deliver_goods);
        ButterKnife.bind(this);

        initView();
    }

    private void initView() {
        mImagView.add(mIvOne);
        mImagView.add(mIvSecond);
        mImagView.add(mIvThird);
    }

    @OnClick({R.id.tv_shopcart_edit,R.id.iv_one, R.id.iv_second, R.id.iv_third, R.id.tv_commit})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_shopcart_edit:
                finish();
                break;

            case R.id.iv_one:
                setCashPay();
                selectPayMethod(0);
                break;

            case R.id.iv_second:
                setPosPay();
                selectPayMethod(1);
                break;

            case R.id.iv_third:
                setAliPay();
                selectPayMethod(2);
                break;

            case R.id.tv_commit:
                finish();
                break;
        }
    }

    public void selectPayMethod(int k){
        for (int i = 0; i < mImagView.size(); i++) {
            if (i==k) {
                mImagView.get(i).setImageResource(R.drawable.ischeck);
            }else {
                mImagView.get(i).setImageResource(R.drawable.nocheck);
            }
        }
    }

    private void setCashPay() {

        Intent intent = new Intent();
        intent.putExtra("type", 0);
        setResult(Constant.DELIVERY_REQUEST_CODE, intent);
    }

    private void setPosPay() {
        Intent intent = new Intent();
        intent.putExtra("type", 1);;
        setResult(Constant.DELIVERY_REQUEST_CODE, intent);
    }

    private void setAliPay() {
        Intent intent = new Intent();
        intent.putExtra("type", 2);
        setResult(Constant.DELIVERY_REQUEST_CODE, intent);
    }
}
